package com.gcb.controller.system.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.gcb.common.utils.poi.ExcelUtil;
import com.gcb.controller.BaseController;
import com.gcb.controller.system.domain.GcbOpenCity;
import com.gcb.controller.system.service.IGcbOpenCityService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gcb.common.annotation.Log;
import com.gcb.common.core.domain.AjaxResult;
import com.gcb.common.enums.BusinessType;
import com.gcb.common.core.page.TableDataInfo;

/**
 * 开通运营的城市Controller
 *
 * @author ruoyi
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/system/city")
public class GcbOpenCityController extends BaseController {
    @Autowired
    private IGcbOpenCityService gcbOpenCityService;

    /**
     * 查询开通运营的城市列表
     */
    @PreAuthorize("@ss.hasPermi('system:city:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcbOpenCity gcbOpenCity) {
        startPage();
        List<GcbOpenCity> list = gcbOpenCityService.selectGcbOpenCityList(gcbOpenCity);
        return getDataTable(list);
    }

    /**
     * 查询开通运营的城市列表
     */
    @PreAuthorize("@ss.hasPermi('system:city:list')")
    @PostMapping("/page")
    public TableDataInfo page(@RequestBody GcbOpenCity gcbOpenCity) {
        startPage();
        List<GcbOpenCity> list = gcbOpenCityService.selectGcbOpenCityList(gcbOpenCity).stream().map(item -> {
            item.setStatus(1);
            item.setStatusStr("启用");
            return item;
        }).collect(Collectors.toList());
        return getDataTable(list);
    }

    /**
     * 导出开通运营的城市列表
     */
    @PreAuthorize("@ss.hasPermi('system:city:export')")
    @Log(title = "开通运营的城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GcbOpenCity gcbOpenCity) {
        List<GcbOpenCity> list = gcbOpenCityService.selectGcbOpenCityList(gcbOpenCity);
        ExcelUtil<GcbOpenCity> util = new ExcelUtil<GcbOpenCity>(GcbOpenCity. class);
        util.exportExcel(response, list, "开通运营的城市数据");
    }

    /**
     * 获取开通运营的城市详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:city:query')")
    @GetMapping(value = "/query/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(gcbOpenCityService.selectGcbOpenCityById(id));
    }

    /**
     * 新增开通运营的城市
     */
    @PreAuthorize("@ss.hasPermi('system:city:add')")
    @Log(title = "开通运营的城市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GcbOpenCity gcbOpenCity) {
        return toAjax(gcbOpenCityService.insertGcbOpenCity(gcbOpenCity));
    }

    /**
     * 修改开通运营的城市
     */
    @PreAuthorize("@ss.hasPermi('system:city:edit')")
    @Log(title = "开通运营的城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GcbOpenCity gcbOpenCity) {
        return toAjax(gcbOpenCityService.updateGcbOpenCity(gcbOpenCity));
    }

    /**
     * 删除开通运营的城市
     */
    @PreAuthorize("@ss.hasPermi('system:city:remove')")
    @Log(title = "开通运营的城市", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gcbOpenCityService.deleteGcbOpenCityByIds(ids));
    }
}
